class ParseUtils{
	private static _instance:ParseUtils;
	public constructor() {
		
	}
	public static getInstance():ParseUtils{
		if(!this._instance){
			this._instance=new ParseUtils();
		}
		return this._instance;
	}
	/**
	 * 时间解析
	 * @param time 要转换的毫秒数
	 * @param type 返回样式，可自己扩展.默认1,返回:1970.01.01
	 * @{type=1} return: 1970.01.01
	 * @{type=2} return: 01月02日 10:02
	 * @{type=3} return: 1970.01.01 10:05
	 */
	public parseTime(time: number, type: number = 1) {
		let oDate = new Date(time);
		let oYear = oDate.getFullYear();
		let oMonth = oDate.getMonth() + 1;
		let oDay = oDate.getDate();
		let oHour = oDate.getHours();
		let oMin = oDate.getMinutes();
		let oSen = oDate.getSeconds();

		let oTime = "";
		// oTime = oYear +'-'+ this.getzf(oMonth) +'-'+ this.getzf(oDay) +' '+ this.getzf(oHour) +':'+ this.getzf(oMin) +':'+this.getzf(oSen);//最后拼接时间 
		if (type == 1) {
			oTime = oYear + '.' + this.getzf(oMonth) + '.' + this.getzf(oDay);//最后拼接时间 
		} else if (type == 2) {
			oTime = this.getzf(oMonth) + '月' + this.getzf(oDay) + '日 ' + this.getzf(oHour) + ':' + this.getzf(oMin);//最后拼接时间 
		} else if (type == 3) {
			oTime = oYear + '.' + this.getzf(oMonth) + '.' + this.getzf(oDay) + "  " + this.getzf(oHour) + ':' + this.getzf(oMin);//最后拼接时间                 
		} else if (type == 4) {
			oTime = this.getzf(oHour) + ':' + this.getzf(oMin);//最后拼接时间 
		}
		return oTime;
	}
	//补0操作  
	private getzf(num) {
		if (parseInt(num) < 10) {
			num = '0' + num;
		}
		return num;
	}
	/**
	 * 名字解析
	 * @parse name 要解析的名字
	 * @parse len 最长占用的字节数（大写字母占2个），默认为10.
	 */
	public parseName(name: string, len: number = 10) {
		let rname = "";
		for (let i = 0; i < name.length; i++) {
			let unicode = name.charCodeAt(i);
			if ((unicode > 19968 && unicode < 40869) || (unicode > 65 && unicode < 90)) {
				if (len - 2 < 0) {
					rname += "...";
					return rname;
				} else if (len - 2 == 0) {
					rname += name[i];
					if (name != rname) {
						rname += "...";
					}
					return rname;
				} else {
					rname += name[i];
				}
				len -= 2;
			} else {
				if (len - 1 < 0) {
					rname += "...";
					return rname;
				} else if (len - 1 == 0) {
					rname += name[i];
					if (name != rname) {
						rname += "...";
					}
					return rname;
				} else {
					rname += name[i];
				}
				len -= 1;
			}
		}
		return rname;
	}
}